from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-14 14:08:28.061374
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 14, Nov, 2022
Time: 14:08:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.9419
Nobs: 840.000 HQIC: -51.2547
Log likelihood: 10971.4 FPE: 4.52858e-23
AIC: -51.4491 Det(Omega_mle): 4.07104e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298736 0.050680 5.895 0.000
L1.Burgenland 0.110030 0.034815 3.160 0.002
L1.Kärnten -0.106065 0.018553 -5.717 0.000
L1.Niederösterreich 0.210816 0.072841 2.894 0.004
L1.Oberösterreich 0.101241 0.069262 1.462 0.144
L1.Salzburg 0.251809 0.036932 6.818 0.000
L1.Steiermark 0.037443 0.048424 0.773 0.439
L1.Tirol 0.107408 0.039250 2.737 0.006
L1.Vorarlberg -0.060231 0.033843 -1.780 0.075
L1.Wien 0.052961 0.061977 0.855 0.393
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067473 0.104528 0.645 0.519
L1.Burgenland -0.030379 0.071806 -0.423 0.672
L1.Kärnten 0.047619 0.038265 1.244 0.213
L1.Niederösterreich -0.173569 0.150235 -1.155 0.248
L1.Oberösterreich 0.379369 0.142854 2.656 0.008
L1.Salzburg 0.288298 0.076173 3.785 0.000
L1.Steiermark 0.107607 0.099875 1.077 0.281
L1.Tirol 0.315795 0.080954 3.901 0.000
L1.Vorarlberg 0.023058 0.069802 0.330 0.741
L1.Wien -0.018921 0.127828 -0.148 0.882
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197519 0.026234 7.529 0.000
L1.Burgenland 0.092539 0.018022 5.135 0.000
L1.Kärnten -0.008757 0.009604 -0.912 0.362
L1.Niederösterreich 0.267867 0.037706 7.104 0.000
L1.Oberösterreich 0.115241 0.035853 3.214 0.001
L1.Salzburg 0.052598 0.019118 2.751 0.006
L1.Steiermark 0.016432 0.025066 0.656 0.512
L1.Tirol 0.098438 0.020318 4.845 0.000
L1.Vorarlberg 0.056162 0.017519 3.206 0.001
L1.Wien 0.113008 0.032082 3.522 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105260 0.026883 3.915 0.000
L1.Burgenland 0.047132 0.018468 2.552 0.011
L1.Kärnten -0.017195 0.009841 -1.747 0.081
L1.Niederösterreich 0.197168 0.038639 5.103 0.000
L1.Oberösterreich 0.280199 0.036740 7.626 0.000
L1.Salzburg 0.120761 0.019591 6.164 0.000
L1.Steiermark 0.101541 0.025687 3.953 0.000
L1.Tirol 0.123250 0.020820 5.920 0.000
L1.Vorarlberg 0.069045 0.017952 3.846 0.000
L1.Wien -0.027940 0.032876 -0.850 0.395
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130255 0.048706 2.674 0.007
L1.Burgenland -0.049505 0.033458 -1.480 0.139
L1.Kärnten -0.039662 0.017830 -2.224 0.026
L1.Niederösterreich 0.165955 0.070003 2.371 0.018
L1.Oberösterreich 0.139120 0.066564 2.090 0.037
L1.Salzburg 0.285186 0.035493 8.035 0.000
L1.Steiermark 0.032845 0.046537 0.706 0.480
L1.Tirol 0.163486 0.037721 4.334 0.000
L1.Vorarlberg 0.103949 0.032524 3.196 0.001
L1.Wien 0.070126 0.059562 1.177 0.239
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058976 0.038583 1.529 0.126
L1.Burgenland 0.042730 0.026504 1.612 0.107
L1.Kärnten 0.049815 0.014124 3.527 0.000
L1.Niederösterreich 0.228090 0.055453 4.113 0.000
L1.Oberösterreich 0.272517 0.052729 5.168 0.000
L1.Salzburg 0.058289 0.028116 2.073 0.038
L1.Steiermark -0.006936 0.036865 -0.188 0.851
L1.Tirol 0.156279 0.029881 5.230 0.000
L1.Vorarlberg 0.067872 0.025765 2.634 0.008
L1.Wien 0.072872 0.047183 1.544 0.122
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184597 0.046183 3.997 0.000
L1.Burgenland -0.004499 0.031726 -0.142 0.887
L1.Kärnten -0.060875 0.016907 -3.601 0.000
L1.Niederösterreich -0.086203 0.066378 -1.299 0.194
L1.Oberösterreich 0.192429 0.063117 3.049 0.002
L1.Salzburg 0.059610 0.033655 1.771 0.077
L1.Steiermark 0.225934 0.044127 5.120 0.000
L1.Tirol 0.494615 0.035768 13.829 0.000
L1.Vorarlberg 0.047556 0.030840 1.542 0.123
L1.Wien -0.051201 0.056478 -0.907 0.365
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158599 0.052590 3.016 0.003
L1.Burgenland -0.009306 0.036127 -0.258 0.797
L1.Kärnten 0.064830 0.019252 3.367 0.001
L1.Niederösterreich 0.203752 0.075586 2.696 0.007
L1.Oberösterreich -0.067687 0.071872 -0.942 0.346
L1.Salzburg 0.223331 0.038324 5.827 0.000
L1.Steiermark 0.113424 0.050249 2.257 0.024
L1.Tirol 0.084101 0.040729 2.065 0.039
L1.Vorarlberg 0.122109 0.035118 3.477 0.001
L1.Wien 0.108440 0.064312 1.686 0.092
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356958 0.030955 11.532 0.000
L1.Burgenland 0.008841 0.021264 0.416 0.678
L1.Kärnten -0.024447 0.011332 -2.157 0.031
L1.Niederösterreich 0.230271 0.044490 5.176 0.000
L1.Oberösterreich 0.158469 0.042305 3.746 0.000
L1.Salzburg 0.054044 0.022558 2.396 0.017
L1.Steiermark -0.018501 0.029577 -0.626 0.532
L1.Tirol 0.116880 0.023974 4.875 0.000
L1.Vorarlberg 0.071647 0.020671 3.466 0.001
L1.Wien 0.046955 0.037855 1.240 0.215
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043709 0.160910 0.192395 0.165750 0.131884 0.124186 0.070082 0.230549
Kärnten 0.043709 1.000000 0.001723 0.131776 0.045142 0.099475 0.427996 -0.050753 0.102174
Niederösterreich 0.160910 0.001723 1.000000 0.345696 0.166488 0.311433 0.127942 0.192299 0.341689
Oberösterreich 0.192395 0.131776 0.345696 1.000000 0.235919 0.341072 0.178202 0.180165 0.275313
Salzburg 0.165750 0.045142 0.166488 0.235919 1.000000 0.153307 0.145363 0.152967 0.141544
Steiermark 0.131884 0.099475 0.311433 0.341072 0.153307 1.000000 0.163386 0.148885 0.092559
Tirol 0.124186 0.427996 0.127942 0.178202 0.145363 0.163386 1.000000 0.121838 0.163788
Vorarlberg 0.070082 -0.050753 0.192299 0.180165 0.152967 0.148885 0.121838 1.000000 0.018048
Wien 0.230549 0.102174 0.341689 0.275313 0.141544 0.092559 0.163788 0.018048 1.000000